<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/21
 * Time: 14:41
 */

namespace Home\Controller;
use Home\Model\UserModel;
use Think\Controller;
use Think\Model;

class UserController extends BaseController {


    /*
     * 上传毕业学校名称
     * @param  int $id //用户的id
     * @param string $school //毕业学校名称
     * return json
     */
    public function education_auth()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $school = I('post.school');
        $condition['user_id'] = $id;
        $data = array(
            'education'=>$school
        );
        $res = $model->where($condition)->save($data);
        if($res)
        {
            $result = array(
                'msg'=>'success'
            );
        }else{
            $result = array(
                'msg'=>'failed'
            );
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
     * 上传房屋认证信息
     * @param int $id //用户唯一id
     * @param array $data  //房屋认证信息
     * @return json
     */
    public function house_auth()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $house_case = I('post.house_case');
        $house_local = I('post.house_local');
        $house_view = I('post.house_view');
        $data = array(
            'house_case'=>$house_case,
            'house_local'=>$house_local,
            'house_view'=>$house_view
        );
        $condition['user_id'] = $id;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
     * 上传车辆认证信息
     * @param int $id//用户id
     * @param array $data//车辆认证信息
     * @return json
     */
    public function car_auth()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $car_case = I('post.car_case');
        $car_log = I('post.car_log');
        $car_view = I('post.car_view');
        $condition['user_id'] = $id;
        $data = array(
            'car_case'=>$car_case,
            'car_log'=>$car_log,
            'car_view'=>$car_view
        );
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
     * 上传自我介绍信息
     * @param int $id //用户id
     * @param array $data //自我介绍信息
     * @return json
     */
    public function self_introduction()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $self_introduction = I('post.introduction');
        $data['self_introduction'] = $self_introduction;
        $condition['user_id'] = $id;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }


    /*
     * 编辑个人资料
     * @param int $id
     * @param string $action //编辑资料的字段名
     * @param string $detail //编辑资料字段的详细内容
     * @return json
     */
    public function edit_detail()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $action = I('post.action');
        $detail = I('post.detail');
        $condition['user_id'] = $id;
        if($action=='city'||$action=='register')
        {
            $arr = explode(',',$detail);
            $detail = $arr[0];
            $city = $this->select_city_id($detail);
            $data[$action] = $city;
        }else {
            $data[$action] = $detail;
        }
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
  * 通过城市名查询在数据库表总的id
  * @param string $city //传入的城市名
  * @param return $id //返回查询到的id
  */
    public function select_city_id($city)
    {
        $model = M('region');
        $condition['region_name'] = $city;
        $data = $model->where($condition)->select();
        $id = $data[0]['id'];
        return $id;
    }

    /*
     * 上传身份认证信息
     * @param int $id //用户id
     * @param array $data //身份认证 的信息
     * @return json
     */
    public function edit_identity()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $data = I('post.');
        $condition['user_id'] = $id;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result = array(
                'msg'=>'success',
                'statu'=>1
            );
        }else{
            $result = array(
                'msg'=>'failed',
                'statu'=>2
            );
        }
        echo json_encode($result);
    }

    /*
     * 上传家庭背景
     *@param int $id  //用户的唯一识别id
     * @param array $data //家庭背景信息
     * @return json
     */
    public function family_background()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $family_background = I('post.family_background');
        $condition['user_id'] = $id;
        $data['family_background'] = $family_background;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
     * 上传个人职业规划信息
     * @param int $id //用户id
     * @param array $data //职业规划的信息
     *@param json $result //返回上传状态
     */
    public function career_planning()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $career_planning = I('post.career_planning');
        $condition['user_id'] = $id;
        $data['career_planning'] = $career_planning;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    /*
     * 上传个人的情感经历
     * @param int $id //用户id
     * @param array $data //情感经历
     * @param return $result //返回上传的状态信息
     */
    public function emotion()
    {
        $model = M('userinfo');
        $id = I('post.id');
        $emotion = I('post.emotion');
        $condition['user_id'] = $id;
        $data['emotion'] = $emotion;
        $res = $model->where($condition)->save($data);
        if(!empty($res))
        {
            $result['msg'] = 'success';
        }else{
            $result['msg'] = 'failed';
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }


    //上传图片接口1:用户个人资料，2学历照片，3资产认证照房，4资产认证照车
    /*
     * 上传图片接口
     * @param int $user_id //用户的id
     * @param int $type //1:用户个人资料，2学历照片，3资产认证照房，4资产认证照车
     * @param array $data //需要写入数据库的信息
     * @param return json $result //返回的上传状态信息
     */
    public function upload_pic()
    {
        $user_id = I('post.id');
        $type = I('post.type');
        $result['user_id'] = $user_id;
        if(!empty($_FILES['pic'])) {
            $this->upload_curl_pic($_FILES['pic']['tmp_name'],$user_id,$type);
        }
        $data = array(
            'msg'=>'上传成功！',
            'statu'=>1
        );
        echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }


//    public function upload_ceshi()
//    {
//        $count = count($_FILES['pic']['tmp_name']);
////        var_dump($_FILES);
//        $user_id = I('post.id');
//        $type = I('post.type');
//        $result['user_id'] = $user_id;
//        if(!empty($_FILES['pic']))
//        {
//            for($i=0;$i<$count;$i++)
//            {
//                $this->upload_curl_pic($_FILES['pic']['tmp_name'][$i], $user_id, $type);
//            }
//        }
//        $data = array(
//            'msg'=>'上传成功！',
//            'statu'=>1
//        );
//        echo json_encode($data,JSON_UNESCAPED_UNICODE);
//    }

    /*
     * 上传个人头像照片
     * @param int $user_id //用户id
     * @param array $data //用户的头像信息
     * @param return json $result //返回上传的状态信息
     */
    public function upload_header_pic()
    {
        $user_id = I('post.id');
        if(!empty($_FILES['pic'])) {
            $model = M('userinfo');
            $setting=C('UPLOAD_SITEIMG_QINIU');
            $Upload = new \Think\Upload($setting);
            $info = $Upload->upload($_FILES);
            //验证图片 如果不是人的头像 就自动审核不通过   再返回一个值 ，提示图片不合格
            $url = $info['pic']['url'];
            $data['header_pic'] = $url;
            $condition['user_id'] = $user_id;
            $res = $model->where($condition)->save($data);
            if(!empty($res))
            {
                $result = array(
                    'msg'=>'header image upload success!',
                    'statu'=>1,
                    'url'=>$url,
                );
            }else{
                $result = array(
                    'msg'=>'header image upload failed',
                    'error'=>404
                );
            }
        }else{
            $result = array(
                'msg'=>'image is not post success',
                'error'=>'500'
            );
        }
        echo json_encode($result);
    }

    /*
     * 个人中心资料信息读取
     * @param int $myId //自己的id
     * @param int $id //查看个人中心资料的相应人id
     * @param json //返回查询到的资料
     *
     */
    public function my_condition()
    {
        $myId = I('get.myid');
        $id = I('get.id');
        $model = new Model();
        $fsql = "select a.user_id,a.uid,a.nickname,a.nation,a.self_introduction,a.mate_selection,a.family_background,a.birthday,a.constellation,a.career_planning,a.emotion,a.header_pic,a.real_name,
        a.identity_card,c.region_name as register,d.statu from wl_userinfo a left join wl_region b on a.register=b.id left join wl_region c on b.parent_id=c.id left join wl_user d on
         a.user_id=d.id  where a.user_id=$id";
        $frist = $model->query($fsql);
        $data = $frist[0];
        $ssql = "select YEAR(CURDATE()) - YEAR (a.birthday) as age,a.height,b.region_name,d.content as annual_income,e.content as hope_marry_time from
        wl_userinfo a left join wl_region b on a.city=b.id  left join wl_income d on a.annual_income=d.id
        left join wl_marry e on a.hope_marry_time=e.id where a.user_id=$id";
        $second = $model->query($ssql);
        $data['common_data'] = $second[0];
        //根据id倒叙显示 
        $msql = "select  id,pic_url,width,height from wl_images where user_id=$id and type=5 and status=1 order by id desc ";
        $images = $model->query($msql);
        $data['images'] = $images;
        $tsql = "select a.type,b.education_auth,b.house_auth,b.car_auth from wl_user a left join wl_userinfo b on a.id=b.user_id where a.id=$id ";
        $auth = $model->query($tsql);
        $bsql = "select count(*) as beat from wl_heart where tobeat=$id";
        $num = $model->query($bsql);
        $data['beat'] =$num[0]['beat'];
        if($auth[0]['type']==2)
        {
            $sql = "select identity_auth_time from wl_user where id=$id";
            $identity_time = $model->query($sql);
            $auth_array['identity_auth']['statu']=2;
            $auth_array['identity_auth']['msg'] = 'identity has already auth';
            $auth_array['identity_auth']['auth_time']=$identity_time[0]['identity_auth_time'];
        }else{
            $auth_array['identity_auth']['statu']=1;
            $auth_array['identity_auth']['msg'] = 'identity has not auth';
        }
        if($auth[0]['education_auth']==2)
        {
            $sql = "select education_auth_time from wl_userinfo where user_id=$id";
            $education_auth = $model->query($sql);
            $auth_array['education_auth']['statu']=2;
            $auth_array['education_auth']['msg'] = 'education has already auth';
            $auth_array['education_auth']['auth_time']=$education_auth['education_auth_time'];
        }else{
            $auth_array['education_auth']['statu']=1;
            $auth_array['education_auth']['msg'] = 'education has not auth';
        }
        if($auth[0]['house_auth']==2)
        {
            $sql = "select house_auth_time from wl_userinfo where user_id=$id";
            $house_auth = $model->query($sql);
            $auth_array['house_auth']['statu']=2;
            $auth_array['house_auth']['msg'] = 'house has already auth';
            $auth_array['house_auth']['house_auth_time']=$house_auth['house_auth_time'];
        }else{
            $auth_array['house_auth']['statu']=1;
            $auth_array['house_auth']['msg'] = 'house has not auth';
        }
        if($auth[0]['car_auth']==2)
        {
            $sql = "select car_auth_time from wl_userinfo where user_id=$id";
            $car_auth = $model->query($sql);
            $auth_array['car_auth']['statu']=2;
            $auth_array['car_auth']['msg'] = 'car has already auth';
            $auth_array['car_auth']['car_auth_time']=$car_auth['car_auth_time'];
        }else{
            $auth_array['car_auth']['statu']=1;
            $auth_array['car_auth']['msg'] = 'car has not auth';
        }
        $data['auth']=$auth_array;
        if(!empty($myId))
        {
            $btsql = "select * from wl_heart where frombeat=$myId and tobeat=$id";
            $bres = $model->query($btsql);
            if(!empty($bres))
            {
                $data['is_beat'] = '1';
            }else{
                $data['is_beat'] = '2';
            }
        }
        if($data['statu']==2)
        {
            $User = new UserModel();
            $day = intval($User->search_day($id));
            if($day>10){
            	//超过10天 显示大于10天
            	$data['left_day']="is vip and gt 10 days!";
            }elseif($day>0){
            	//小于10天 显示天数
            	$data['left_day'] = strval($day);
            }else{
            	//会员过期，显示不是会员
            	$data['left_day'] = 'is not vip!';
            	$id=intval($id);
            	if($id!=283){
            		//设置他的状态为非会员状态
            		$userModel=new UserModel();
            		$result=$userModel->chale_vip($id);
            	}
            	
            }
           
        }else{
             $data['left_day'] = 'is not vip!';
        }
        if(empty($myId))
        {
            //$data['pay_type'] = "1";//pay_type为1就是审核状态，pay_type为2时正常上线状态
            $data['pay_type'] = "2";
        }
        //将访客记录写入数据库
        if(!empty($myId)&&!empty($id))
        {
            $user = new UserModel();
            $user->add_visitor_record($myId,$id);
        }
       echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }

    //最近访客记录
    public function get_visitor_list()
    {
        $user_id =I('get.user_id');
        $User = new UserModel();
        $data = $User->get_visitor_list($user_id);
        echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }



    /*
     * 聊天成功时将聊天双方的id信息写入数据库
     * @param array $data 写入数据
     * return 写入数据的状态
     */
    public function add_chat_record()
    {
       $model = M('chat');
        $data = array(
            'user_id'=>I('post.user_id'),
            'chat_id'=>I('post.chat_id'),
            'chat_time'=>date('y-m-d H:i:s',time()),
        );
        $res = $model->data($data)->add();
        if(!empty($res))
        {
            $result = array(
                'msg'=>'add chat record success!',
                'statu'=>1
            );
        }else{
            $result = array(
                'msg'=>'add chat record failed!',
                'statu'=>2
            );
        }
        echo json_encode($result);
    }

    //判断当日的聊天次数
    public function judge_chat_times()
    {
       $id = I('get.id');
        $chat_id = I('chat_id');
        $model = new UserModel();
        $is_chat = $model->judge_is_chat($id,$chat_id);
        if(!empty($is_chat))
        {
            $data = array(
                'msg'=>'this day you have been chat with this person',
                'statu'=>3,
            );
            echo json_encode($data);
            exit;
        }
        $res = parent::check_vip($id,2);
        if(empty($res))
        {
            $data = array(
                'msg'=>'the chat time is out 3 times this day',
                'error'=>'out of time limit',
                'statu'=>2
            );
        }else{
            $data = array(
                'msg'=>'you can chat',
                'statu'=>1
            );
        }
        echo json_encode($data);
    }


    /*
     * @param int $id //用户的id
     * @param json $result //通过id请求融云获取的token
     */
    public function get_token()
    {
        $model = new Model();
        $user_id = I('get.id');
        $sql ="select nickname,header_pic from wl_userinfo where user_id = $user_id";
        $data = $model->query($sql);
        $postArr = array(
            'userId'=>$user_id,
            'name'=>$data[0]['nickname'],
            'portraitUri'=>$data[0]['header_pic']
        );
        $url = 'http://api.cn.ronghub.com/user/getToken.json';
        $headers =$this->get_headers();
        $result = $this->curlPost( $url,$postArr,$headers);
       echo $result;
    }
    /**
     * 新融云账号
     */
    public function get_tokenB(){
    	$model = new Model();
    	$user_id = I('get.id');
    	$sql ="select nickname,header_pic from wl_userinfo where user_id = $user_id";
    	$data = $model->query($sql);
    	$postArr = array(
    			'userId'=>$user_id,
    			'name'=>$data[0]['nickname'],
    			'portraitUri'=>$data[0]['header_pic']
    	);
    	$url = 'http://api.cn.ronghub.com/user/getToken.json';
    	$headers =$this->get_headersB();
    	$result = $this->curlPost( $url,$postArr,$headers);
    	echo $result;
    }
    /*
     * 获取请求头
     * @App-Key 融云的key
     * @appsecret 融云的secret
     * @param return //返回签名信息
     */
    public function get_headers()
    {
        srand((double)microtime()*1000000);
        $appSecret = 'ADeLIGYK4T';//开发者平台分配的开发环境 App Secret。
        $nonce = rand(); // 获取随机数。
        $timestamp = time(); // 获取时间戳。
        $signature = sha1($appSecret.$nonce.$timestamp);
        //old App-Key x4vkb1qpvxjkk  ADeLIGYK4T  AppKey：qf3d5gbjqfvah App Secret：5VDB1tRHKyH
        return array(
            'App-Key:'.'x4vkb1qpvxjkk',
            'Nonce:'.$nonce,
            'Timestamp:'.$timestamp,
            'Signature:'.$signature,
            'Content-Type:Application/x-www-form-urlencoded',
        );
    }
    /**
     * 新的融云账号
     */
    public function  get_headersB(){
    	srand((double)microtime()*1000000);
    	$appSecret = '5VDB1tRHKyH';//开发者平台分配的开发环境 App Secret。
    	$nonce = rand(); // 获取随机数。
    	$timestamp = time(); // 获取时间戳。
    	$signature = sha1($appSecret.$nonce.$timestamp);
    	//old App-Key x4vkb1qpvxjkk  ADeLIGYK4T  AppKey：qf3d5gbjqfvah App Secret：5VDB1tRHKyH
    	return array(
    			'App-Key:'.'qf3d5gbjqfvah',
    			'Nonce:'.$nonce,
    			'Timestamp:'.$timestamp,
    			'Signature:'.$signature,
    			'Content-Type:Application/x-www-form-urlencoded',
    	);
    }

    //发送消息
    public function send_message()
    {
        $content = 'content={\"content\":\"c#hello\"}&fromUserId=285&toUserId=2191&toUserId=2192&objectName=RC:TxtMsg&pushContent=thisisapush&pushData={\"pushData\":\"hello\"}';
        $url = "http://api.cn.ronghub.com/message/system/publish_template.json";
        $headers = $this->get_headers();
        $result = $this->curlPost($url,$content,$headers);
        echo $result;
    }

        /**
     * 通过CURL发送HTTP请求
     * @param string $url  //请求URL
     * @param array $postFields //请求参数
     * @return mixed
     */
    private function curlPost($url,$postFields,$headers){

        $ch = curl_init ();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); //处理http证书问题
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $ret = curl_exec($ch);
        if (false === $ret) {
            $ret =  curl_errno($ch);
        }
        curl_close($ch);
        return $ret;
    }



    /*
     * 删除照片
     * @param int $id 照片id
     * @return json //返回删除状态信息
     */
    public function delete_pic()
    {
        $pic_id = I('get.pic_id');
        $model = M('images');
        $condition['id'] = $pic_id;
        $res = $model->where($condition)->delete();
        if(!empty($res))
        {
            $data = array(
                'statu'=>1,
                'msg'=>'delete pic success!',
            );
        }else{
            $data = array(
                'statu'=>2,
                'msg'=>'delete pic failed!',
            );
        }
        echo json_encode($data);
    }

    /*
     * @param int $id //用户的id
     * @param array $data //查询到的身份信息
     * @reutn //返回身份信息
     */
    public function get_identify_photo()
    {
        $id = I('get.id');
        $model = new Model();
        $sql = "select a.pic_url as zhengmian,b.pic_url as fanmian from wl_images a,wl_images b where a.user_id=$id and a.type=1 and b.user_id=$id and b.type=11";
        $data = $model->query($sql);
     echo json_encode($data);
    }

    /*
     * @param int $user_id //用户的id
     * @param string $birthday //用户的生日信息
     * @param reutn json //返回查询到的星座信息
     */
    public function get_star()
    {
        $model = M('userinfo');
        $user_id = I('post.user_id');
        $birthday = I('post.birthday');
        $data = explode('-',$birthday);
        $month = $data[1];
        $day = $data[2];
        $star = $this->getstar($month,$day);
        $condition['user_id'] = $user_id;
        $result['constellation'] = $star;
        $result['birthday'] = $birthday;
        $res = $model->where($condition)->save($result);
       if(!empty($res))
       {
           $back = array(
               'msg'=>'save data success',
               'statu'=>1,
               'star'=>$star
           );
       }else{
           $back = array(
               'msg'=>'save data failed',
               'statu'=>2,
               'star'=>$star
           );
       }
        echo json_encode($back,JSON_UNESCAPED_UNICODE);
    }


    /*
     * 根据月份与时间查询星座
     * @param int  $m //查询的月份
     * @param int $d //查询 的日期
     * @return //返回星座信息
     */
    public function getstar($m,$d)
    {
        if ($m == 1) {
            if ($d < 21) {
                return "魔羯座";
            } else {
                return "水瓶座";
            }
        } elseif ($m == 2) {
            if ($d < 20) {
                return "水瓶座";
            } else {
                return "双鱼座";
            }
        } elseif ($m == 3) {
            if ($d < 21) {
                return "双鱼座";
            } else {
                return "白羊座";
            }
        } elseif ($m == 4) {
            if ($d < 21) {
                return "白羊座";
            } else {
                return "金牛座";
            }
        } elseif ($m == 5) {
            if ($d < 22) {
                return "金牛座";
            } else {
                return "双子座";
            }
        } elseif ($m == 6) {
            if ($d < 22) {
                return "双子座";
            } else {
                return "巨蟹座";
            }
        } elseif ($m == 7) {
            if ($d < 23) {
                return "巨蟹座";
            } else {
                return "狮子座";
            }
        } elseif ($m == 8) {
            if ($d < 24) {
                return "狮子座";
            } else {
                return "处女座";
            }
        } elseif ($m == 9) {
            if ($d < 24) {
                return "处女座";
            } else {
                return "天秤座";
            }
        } elseif ($m == 10) {
            if ($d < 24) {
                return "天秤座";
            } else {
                return "天蝎座";
            }
        } elseif ($m == 11) {
            if ($d < 23) {
                return "天蝎座";
            } else {
                return "射手座";
            }
        } elseif ($m == 12) {
            if ($d < 22) {
                return "射手座";
            } else {
                return "魔羯座";
            }
        }
    }

    /*
     * 获取心动列表
     * @param int $user_id //用户的id
     * @param int $type //type为1时获取对自己心动列表 ，type为2获取自己对别人的心动列表
     * @param json $data //返回查询到的json数组
     */
    public function get_heart_list()
    {
        $model = new Model();
        $user_id = I('get.id');
        $type = I('get.type');
        if($type==1)
        {
            $sql = "select a.beatime,b.header_pic,b.nickname,b.user_id,YEAR(CURDATE()) - YEAR (b.birthday) as age,b.education_auth,b.house_auth,b.car_auth,c.region_name,d.content as annual_income,e.type from wl_heart a left join wl_userinfo b on a.frombeat=b.user_id
       left join wl_region c on b.city=c.id left  join wl_income d on b.annual_income=d.id left join wl_user e on a.frombeat=e.id where a.tobeat=$user_id and b.header_pic!=''";
        }else if($type==2)
        {
            $sql = "select a.beatime,b.header_pic,b.nickname,b.user_id,YEAR(CURDATE()) - YEAR (b.birthday) as age,b.education_auth,b.house_auth,b.car_auth,c.region_name,d.content as annual_income,e.type from wl_heart a left join wl_userinfo b on a.tobeat=b.user_id
       left join wl_region c on b.city=c.id left  join wl_income d on b.annual_income=d.id left join wl_user e on a.tobeat=e.id where a.frombeat=$user_id and b.header_pic!=''";
        }
        $data = $model->query($sql);
        echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }

    //择偶标准
    public function marry_selection()
    {
        $user_id = I('post.user_id');
        $action = I('post.action');
        $detail = I('post.detail');
        $User = new UserModel();
        if($action=='city'||$action=='register')
        {
            $detail = $this->select_city_id($detail);
        }

      $result = $User->edit_marry_selection($user_id,$action,$detail);
        if(!empty($result))
        {
            $data = array(
                'msg'=>'success',
                'statu'=>1
            );
        }else{
            $data = array(
                'msg'=>'failed',
                'statu'=>2
            );
        }
        echo json_encode($data);
    }

    //获取择偶标准列表
    public function get_selection_list()
    {
        $user_id = I('get.user_id');
        $User = new UserModel();
        $data = $User->get_selection_list($user_id);
        echo json_encode($data,JSON_UNESCAPED_UNICODE);
    }


}